import java.util.*;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 86136
 * Date: 2024-09-19
 * Time: 15:18
 */
public class Test {
    public static void main(String[] args) {
        LinkedList<Integer> list = new LinkedList<>();
        list.add(11);
        list.add(21);
        list.add(31);
        list.add(41);
        System.out.println("---------LinkedList的遍历---------");
        System.out.println("====== 反向遍历 ListIterator ======");
        ListIterator<Integer> listIterator2 = list.listIterator(list.size());
        while(listIterator2.hasPrevious()) {
            System.out.print(listIterator2.previous() + " ");
        }
        System.out.println();
        System.out.println("====== 正向遍历 ListIterator ======");
        ListIterator<Integer> listIterator = list.listIterator();
        while(listIterator.hasNext()) {
            System.out.print(listIterator.next() + " ");
        }
        System.out.println();
        System.out.println("====== 迭代器 Iterator ======");
        Iterator<Integer> it = list.iterator();
        while(it.hasNext()) {
            System.out.print(it.next() + " ");
        }
        System.out.println();
        System.out.println("====== for each ======");
        for (Integer x:list) {
            System.out.print(x + " ");
        }
        System.out.println();
        System.out.println("====== for ======");
        for (int i = 0; i < list.size(); i++) {
            System.out.print(list.get(i) + " ");
        }
        System.out.println();
    }
    public static void main2(String[] args) {
        LinkedList<Integer> list = new LinkedList<>();
        list.add(2);//尾插
        list.add(3);
        System.out.println(list);
        list.add(1,0);//指定位置插入
        System.out.println(list);
        System.out.println("===========");
        ArrayList<Integer> arrayList = new ArrayList<>();
        arrayList.add(7);
        arrayList.add(9);
        arrayList.add(8);
        list.addAll(arrayList);//尾插arrayList中的元素
        System.out.println(list);
        list.addAll(1,arrayList);//在指定位置插入arrayList中的元素
        System.out.println(list);
        System.out.println("===========");
        list.remove();//删除第一个值,内部调用的是removeFirst
        list.removeFirst();//删除第一个值
        list.removeLast();//删除最后一个值
        list.remove(2);//删除指定位置的值
        System.out.println(list);
        System.out.println("===========");
        System.out.println(list.get(3));//获取下标所在位置元素
        list.set(3,5);//修改下标位置元素
        System.out.println(list);
        System.out.println("===========");
        if(!list.contains(100)) {//判断是否存在
            list.addFirst(100);
        }
        System.out.println(list);
        System.out.println("===========");
        System.out.println(list.indexOf(9));
        System.out.println(list.lastIndexOf(9));
        System.out.println("===========");
        System.out.println(list.subList(1,4));//截取部分list
        List list1 = list.subList(2,4);//截取部分list
        System.out.println(list1);
    }
    public static void main1(String[] args) {
        MyLinkedList list = new MyLinkedList();
//        list.addFirst(1);
//        list.addFirst(2);
//        list.addFirst(3);
//        list.addFirst(4);
//        list.addFirst(5);
        list.addLast(1);
        list.addLast(2);
        list.addLast(3);
        list.addLast(4);
        list.addLast(5);
        list.display();

        list.addIndex(0,0);
        list.addIndex(2,0);
        list.addIndex(7,0);
        list.display();

        list.remove(0);
        list.display();

        list.removeAllKey(0);
        list.display();
        list.clear();

        list.display();
    }
}
